package Servlet.TeacherServlet;

import Entity.SelectCourse;
import Service.TeacherService.TeacherService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
/*
负责教师 修改学生成绩信息 数据接口
 */
@WebServlet(value = "/updateStudentScore")
public class UpdateStudentScore extends HttpServlet {
    private TeacherService teacherService = new TeacherService();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");

        String studentId = request.getParameter("studentId");
        String courseId = request.getParameter("courseId");
        String teacherId = request.getParameter("teacherId");
        float score = Float.parseFloat(request.getParameter("score"));


        SelectCourse selectCourse = new SelectCourse();
        selectCourse.setCourseId(courseId);
        selectCourse.setStudentId(studentId);
        selectCourse.setTeacherId(teacherId);
        selectCourse.setScore(score);

        int status = teacherService.updateStudentScore(selectCourse);

        PrintWriter out = response.getWriter();

        out.print(status);


        out.flush();

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
